package com.cyz.user.userService.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.common.bean.Shop;
import com.cyz.common.bean.UserShop;
import com.cyz.user.userService.ShopService;
import com.cyz.user.userService.UserShopService;
import com.cyz.common.mapper.UserShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 34928
* @description 针对表【user_shop】的数据库操作Service实现
* @createDate 2023-03-01 15:54:02
*/
@Service
public class UserShopServiceImpl extends ServiceImpl<UserShopMapper, UserShop>
    implements UserShopService {

    @Autowired
    private ShopService shopService;

    @Override
    public List<Shop> getShopsByUserId(Integer userId) {
        LambdaQueryWrapper<UserShop> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserShop::getUserId,userId);
        List<UserShop> list = list(lambdaQueryWrapper);
        List<Shop> shops = new ArrayList<>();
        list.stream()
                .map(UserShop::getShopId)
                .forEach(item ->{
                    shops.add(shopService.getById(item));
                });
        return shops;
    }
}




